home *** CD-ROM | disk | FTP | other *** search
- unit PrintObj;
- {unit to programmatically set printer options so that user does not}
- {have to go to the Printer Options Dialog Box}
- {Revision 1.0}
- {-- in the next revision I intend to put more memory checks and add}
- { exception handling}
- { any other suggestions? e-mail CIS70600,3451 or easalgad@icsi.net}
- interface
- uses
- Printers, WinTypes;
- {see the WinTypes unit for constant declarations such as}
- {dmPaper_Letter, dmbin_Upper, etc}
-
- type
- TPrintSet = class (TObject)
- private
- { Private declarations }
- FDevice: PChar;
- FDriver: PChar;
- FPort: PChar;
- FHandle: THandle;
- FDeviceMode: PDevMode;
- protected
- { Protected declarations }
- procedure SetOrientation (Orientation: integer);
- function GetOrientation: integer;
- {-sets/gets the paper orientation}
- procedure SetPaperSize (Size: integer);
- function GetPaperSize: integer;
- {-sets/gets the paper size}
- procedure SetPaperLength (Length: integer);
- function GetPaperLength: integer;
- {-sets/gets the paper length}
- procedure SetPaperWidth (Width: integer);
- function GetPaperWidth: integer;
- {-sets/gets the paper width}
- procedure SetScale (Scale: integer);
- function GetScale: integer;
- {-sets/gets the printer scale (whatever that is)}
- procedure SetCopies (Copies: integer);
- function GetCopies: integer;
- {-sets/gets the number of copies}
- procedure SetBin (Bin: integer);
- function GetBin: integer;
- {-sets/gets the paper bin}
- procedure SetPrintQuality (Quality: integer);
- function GetPrintQuality: integer;
- {-sets/gets the print quality}
- procedure SetColor (Color: integer);
- function GetColor: integer;
- {-sets/gets the color (monochrome or color)}
- procedure SetDuplex (Duplex: integer);
- function GetDuplex: integer;
- {-sets/gets the duplex setting}
- public
- { Public declarations }
- constructor Create;
- {-inititalizes class}
- destructor Destroy; override;
- {-destroys class}
-
- { Property declarations }
- property Orientation: integer read GetOrientation
- write SetOrientation;
- property PaperSize: integer read GetPaperSize
- write SetPaperSize;
- property PaperLength: integer read GetPaperLength
- write SetPaperLength;
- property PaperWidth: integer read GetPaperWidth
- write SetPaperWidth;
- property Scale: integer read GetScale
- write SetScale;
- property Copies: integer read GetCopies
- write SetCopies;
- property Bin: integer read GetBin
- write SetBin;
- property PrintQuality: integer read GetPrintQuality
- write SetPrintQuality;
- property Color: integer read GetColor
- write SetColor;
- property Duplex: integer read GetDuplex
- write SetDuplex;
- end; { TPrintSet }
-
- var
- PrintSet: TPrintSet;
-
- implementation
-
- constructor TPrintSet.Create;
- {-inititalizes class}
- begin
- GetMem (FDevice, 255);
- GetMem (FDriver, 255);
- GetMem (FPort, 255);
- Printer.GetPrinter (FDevice, FDriver, FPort, FHandle);
- if FHandle = 0 then
- begin {driver not loaded}
- Printer.PrinterIndex := Printer.PrinterIndex;
- {-forces Printer object to load driver}
- end; { if... }
- Printer.GetPrinter (FDevice, FDriver, FPort, FHandle);
- if FHandle<>0 then
- begin
- FDeviceMode := Ptr (FHandle, 0);
- {-PDeviceMode now points to Printer.DeviceMode}
- end {:} else
- begin
- FDeviceMode := nil;
- Fail;
- end; { if... }
- end; { TPrintSet.Create }
-
- procedure TPrintSet.SetOrientation (Orientation: integer);
- {-sets the paper orientation}
- begin
- FDeviceMode^.dmOrientation := Orientation;
- end; { TPrintSet.SetOrientation }
-
- function TPrintSet.GetOrientation: integer;
- {-gets the paper orientation}
- begin
- Result := FDeviceMode^.dmOrientation;
- end; { TPrintSet.GetOrientation }
-
- procedure TPrintSet.SetPaperSize (Size: integer);
- {-sets the paper size}
- begin
- FDeviceMode^.dmPaperSize := Size;
- end; { TPrintSet.SetPaperSize }
-
- function TPrintSet.GetPaperSize: integer;
- {-gets the paper size}
- begin
- Result := FDeviceMode^.dmPaperSize;
- end; { TPrintSet.GetPaperSize }
-
- procedure TPrintSet.SetPaperLength (Length: integer);
- {-sets the paper length}
- begin
- FDeviceMode^.dmPaperLength := Length;
- end; { TPrintSet.SetPaperLength }
-
- function TPrintSet.GetPaperLength: integer;
- {-gets the paper length}
- begin
- Result := FDeviceMode^.dmPaperLength;
- end; { TPrintSet.GetPaperLength }
-
- procedure TPrintSet.SetPaperWidth (Width: integer);
- {-sets the paper width}
- begin
- FDeviceMode^.dmPaperWidth := Width;
- end; { TPrintSet.SetPaperWidth }
-
- function TPrintSet.GetPaperWidth: integer;
- {-gets the paper width}
- begin
- Result := FDeviceMode^.dmPaperWidth;
- end; { TPrintSet.GetPaperWidth }
-
- procedure TPrintSet.SetScale (Scale: integer);
- {-sets the printer scale (whatever that is)}
- begin
- FDeviceMode^.dmScale := Scale;
- end; { TPrintSet.SetScale }
-
- function TPrintSet.GetScale: integer;
- {-gets the printer scale}
- begin
- Result := FDeviceMode^.dmScale;
- end; { TPrintSet.GetScale }
-
- procedure TPrintSet.SetCopies (Copies: integer);
- {-sets the number of copies}
- begin
- FDeviceMode^.dmCopies := Copies;
- end; { TPrintSet.SetCopies }
-
- function TPrintSet.GetCopies: integer;
- {-gets the number of copies}
- begin
- Result := FDeviceMode^.dmCopies;
- end; { TPrintSet.GetCopies }
-
- procedure TPrintSet.SetBin (Bin: integer);
- {-sets the paper bin}
- begin
- FDeviceMode^.dmDefaultSource := Bin;
- end; { TPrintSet.SetBin }
-
- function TPrintSet.GetBin: integer;
- {-gets the paper bin}
- begin
- Result := FDeviceMode^.dmDefaultSource;
- end; { TPrintSet.GetBin }
-
- procedure TPrintSet.SetPrintQuality (Quality: integer);
- {-sets the print quality}
- begin
- FDeviceMode^.dmPrintQuality := Quality;
- end; { TPrintSet.SetPrintQuality }
-
- function TPrintSet.GetPrintQuality: integer;
- {-gets the print quality}
- begin
- Result := FDeviceMode^.dmPrintQuality;
- end; { TPrintSet.GetPrintQuality }
-
- procedure TPrintSet.SetColor (Color: integer);
- {-sets the color (monochrome or color)}
- begin
- FDeviceMode^.dmColor:= Color;
- end; { TPrintSet.SetColor }
-
- function TPrintSet.GetColor: integer;
- {-gets the color}
- begin
- Result := FDeviceMode^.dmColor;
- end; { TPrintSet.GetColor }
-
- procedure TPrintSet.SetDuplex (Duplex: integer);
- {-sets the duplex setting}
- begin
- FDeviceMode^.dmDuplex := Duplex;
- end; { TPrintSet.SetDuplex }
-
- function TPrintSet.GetDuplex: integer;
- {-gets the duplex setting}
- begin
- Result := FDeviceMode^.dmDuplex;
- end; { TPrintSet.GetDuplex }
-
- destructor TPrintSet.Destroy;
- {-destroys class}
- begin
- FreeMem (FDevice, 255);
- FreeMem (FDriver, 255);
- FreeMem (FPort, 255);
- end; { TPrintSet.Destroy }
-
- end. { PrintObj }
-